import java.io.*;
import java.net.URL;

/**
 * @author Vincent
 * @time 2015/8/31 16:01
 */
public class SqlUnionUtil {
    public static void main(String[] args) throws IOException {
        URL url = Thread.currentThread().getContextClassLoader().getResource("");
        File file = new File(url.getPath());
        final File parentFile = file.getParentFile().getParentFile();
        String path = parentFile.getPath() + "//sql";
        File sqlFile = new File(path);
        File[] files = sqlFile.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                String name = pathname.getName();
                if (!name.equals("urpAll.sql") && name.endsWith(".sql")) {
                    return true;
                }
                return false;
            }
        });

        File allFile = new File(path + "//urpAll.sql");
        allFile.delete();
        allFile.createNewFile();
        
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(allFile),"utf-8"));

        for (File f : files) {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f), "utf-8"));

            String s = "";
            while ((s = in.readLine()) != null) {
                writer.write(s + "\n\r");
            }
           in.close();
        }
        writer.close();
        System.out.println("合并完成");
    }
}
